package com.example.db.sensors;

import java.util.Map;

import com.example.db.AbstractDBAction;
import com.example.db.Constants;
import com.example.messaging.MessageFactory;
import com.example.sensors.Sensor_PhoneLock;
import com.example.singletones.SQLHelper;

public class SensorPhoneLockDBWriter extends AbstractDBAction {

	public SensorPhoneLockDBWriter(SQLHelper sqlHelper) {
		super(sqlHelper);
	}

	@Override
	public void updateDB(Object sender, Map<String, Object> args) {
		sqlHelper.insertMainEventCat(args);
	}

	@Override
	public boolean isApplicable(Object sender, Map<String, Object> args) {
		return (sender instanceof Sensor_PhoneLock && args.get("eventType")
				.equals("sensorInfoReceived"));
	}

	public String getName() {
		return Sensor_PhoneLock.NAME;
	}

	public String updateParameter(String parameter, String str) {
		String parameterName = parameter.substring(parameter.indexOf('|') + 1,
				parameter.length() - 1);
		String sensorName = getName();
		int parameterLocation = MessageFactory.getInstance()
				.getParameterNumber(sensorName, parameterName);
		return str.replace(parameter, "value_" + Constants.SENSOR_NAME_POS
				+ "='" + sensorName + "' and key_" + parameterLocation + "='"
				+ parameterName + "' and value_" + parameterLocation);
	}

}
